package com.homejoy.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.homejoy.common.annotation.Log;
import com.homejoy.common.core.controller.BaseController;
import com.homejoy.common.core.domain.AjaxResult;
import com.homejoy.common.enums.BusinessType;
import com.homejoy.system.domain.HomejoyPropertyFacility;
import com.homejoy.system.service.IHomejoyPropertyFacilityService;
import com.homejoy.common.utils.poi.ExcelUtil;
import com.homejoy.common.core.page.TableDataInfo;

/**
 * 房源设施Controller
 * 
 * @author homeJoy
 * @date 2025-11-08
 */
@RestController
@RequestMapping("/system/facility")
public class HomejoyPropertyFacilityController extends BaseController
{
    @Autowired
    private IHomejoyPropertyFacilityService homejoyPropertyFacilityService;

    /**
     * 查询房源设施列表
     */
    @PreAuthorize("@ss.hasPermi('system:facility:list')")
    @GetMapping("/list")
    public TableDataInfo list(HomejoyPropertyFacility homejoyPropertyFacility)
    {
        startPage();
        List<HomejoyPropertyFacility> list = homejoyPropertyFacilityService.selectHomejoyPropertyFacilityList(homejoyPropertyFacility);
        return getDataTable(list);
    }

    /**
     * 导出房源设施列表
     */
    @PreAuthorize("@ss.hasPermi('system:facility:export')")
    @Log(title = "房源设施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HomejoyPropertyFacility homejoyPropertyFacility)
    {
        List<HomejoyPropertyFacility> list = homejoyPropertyFacilityService.selectHomejoyPropertyFacilityList(homejoyPropertyFacility);
        ExcelUtil<HomejoyPropertyFacility> util = new ExcelUtil<HomejoyPropertyFacility>(HomejoyPropertyFacility.class);
        util.exportExcel(response, list, "房源设施数据");
    }

    /**
     * 获取房源设施详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:facility:query')")
    @GetMapping(value = "/{facilityId}")
    public AjaxResult getInfo(@PathVariable("facilityId") Long facilityId)
    {
        return success(homejoyPropertyFacilityService.selectHomejoyPropertyFacilityByFacilityId(facilityId));
    }

    /**
     * 新增房源设施
     */
    @PreAuthorize("@ss.hasPermi('system:facility:add')")
    @Log(title = "房源设施", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HomejoyPropertyFacility homejoyPropertyFacility)
    {
        return toAjax(homejoyPropertyFacilityService.insertHomejoyPropertyFacility(homejoyPropertyFacility));
    }

    /**
     * 修改房源设施
     */
    @PreAuthorize("@ss.hasPermi('system:facility:edit')")
    @Log(title = "房源设施", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HomejoyPropertyFacility homejoyPropertyFacility)
    {
        return toAjax(homejoyPropertyFacilityService.updateHomejoyPropertyFacility(homejoyPropertyFacility));
    }

    /**
     * 删除房源设施
     */
    @PreAuthorize("@ss.hasPermi('system:facility:remove')")
    @Log(title = "房源设施", businessType = BusinessType.DELETE)
	@DeleteMapping("/{facilityIds}")
    public AjaxResult remove(@PathVariable Long[] facilityIds)
    {
        return toAjax(homejoyPropertyFacilityService.deleteHomejoyPropertyFacilityByFacilityIds(facilityIds));
    }
}
